package com.jic.veteran.portal.service.impl;

import com.jic.veteran.common.exception.ApiException;
import com.jic.veteran.mapper.AlumniExplainMapper;
import com.jic.veteran.mapper.AlumniInstructionsMapper;
import com.jic.veteran.mapper.AlumniRuleMapper;
import com.jic.veteran.model.*;
import com.jic.veteran.portal.service.AlumniExplainService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 获取校友会介绍、规章、使用说明
 * Created by mars on 2021/11/10.
 */
@Slf4j
@Service
public class AlumniExplainServiceImpl implements AlumniExplainService {
    @Autowired
    private AlumniExplainMapper alumniExplainMapper;
    @Autowired
    private AlumniRuleMapper alumniRuleMapper;
    @Autowired
    private AlumniInstructionsMapper alumniInstructionsMapper;

    /**
     * 获取校友会介绍
     * Created by mars on 2021/11/10.
     */
    @Override
    public AlumniExplain getExplain() {

        AlumniExplainExample alumniExplainExample = new AlumniExplainExample();
        AlumniExplainExample.Criteria criteria = alumniExplainExample.createCriteria();
        criteria.andStatusEqualTo(1);
        AlumniExplain alumniExplain = alumniExplainMapper.selectByExampleWithBLOBs(alumniExplainExample).get(0);
        if (alumniExplain.getId() == null || alumniExplain.getContent() == null) {
            throw new ApiException("未找到详情信息");
        }
        return alumniExplain;
    }

    /**
     * 获取校友会规则
     * Created by mars on 2021/11/11.
     */
    @Override
    public AlumniRule getRule() {

        AlumniRuleExample alumniRuleExample = new AlumniRuleExample();
        AlumniRuleExample.Criteria criteria = alumniRuleExample.createCriteria();
        criteria.andStatusEqualTo(1);
        AlumniRule alumniRule = alumniRuleMapper.selectByExampleWithBLOBs(alumniRuleExample).get(0);
        if (alumniRule.getId() == null || alumniRule.getContent() == null) {
            throw new ApiException("未找到详情信息");
        }
        return alumniRule;
    }

    /**
     * 获取校友会说明
     * Created by mars on 2021/11/11.
     */
    @Override
    public AlumniInstructions getAlumniInstructions() {

        AlumniInstructionsExample alumniInstructionsExample = new AlumniInstructionsExample();
        AlumniInstructionsExample.Criteria criteria = alumniInstructionsExample.createCriteria();
        criteria.andStatusEqualTo(1);
        AlumniInstructions alumniInstructions = alumniInstructionsMapper.selectByExampleWithBLOBs(alumniInstructionsExample).get(0);
        if (alumniInstructions.getId() == null || alumniInstructions.getContent() == null) {
            throw new ApiException("未找到详情信息");
        }
        return alumniInstructions;

    }
}
